import Vue from "vue";
import Router from "vue-router";
import routers from "./routers";
import store from "../store/index.js";
import { MessageBox } from 'element-ui';
Vue.use(Router);

/**
 * constantRoutes
 *没有权限要求的基本页面
 *所有角色都可以访问
 */
export const constantRoutes = routers;

const createRouter = () =>
  new Router({
    // mode: 'history', // 需要服务支持
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();

router.beforeEach((to, from, next) => {
  // store.commit("user/setTip", true);
  // console.log(store.state.user.tip);
  // MessageBox.alert('<strong style="font-size:18px;color:#000">会员即将过期，请及时续费！</strong>','',{dangerouslyUseHTMLString: true});
  next();
});

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // 重置 路由
}

export default router;
